﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebChamCong.masters
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        private string _userName;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null || Session["userID"] == null)
            {
                Response.Redirect("Default.aspx");
            }

            _userName = Session["fullname"].ToString();

            if (!IsPostBack)
            {
                LoadViews();
            }


        }

        protected void linkButtonFullName_Click(object sender, EventArgs e)
        {
            Response.Redirect(Server.MapPath("UpdateForm.aspx"));
        }

        protected void LinkButtonLogout_Click(object sender, EventArgs e)
        {
            Session["username"] = null;
            Session["userID"] = null;
            Session["fullname"] = null;
            Session["departmentID"] = null;
            Response.Redirect("Default.aspx");
        }

        protected void LoadViews()
        {
            // kiểm tra có phải admin login ko nếu đúng có quyền quản lý
            if (string.Compare(Session["username"].ToString(),"administrator")==0)
            {
                lkb_createAccount.Visible = true;
                lkb_ruleUser.Visible = true;
                lkb_createAccount.Text = Properties.Settings.Default.lb_createAccount;
            }
            else // ngược lại ẩn hết
            {
                DTO.UserRoleDTO kq = BUS.UserRolesBUS.getRoleByUserID(int.Parse(Session["userID"].ToString()));
                if (kq.Action == "14")
                {
                    lkb_Bangiao.Visible = false;
                }
                lkb_createAccount.Visible = false;
                lkb_ruleUser.Visible = false;
            }
            lb_fullName.Text = Properties.Settings.Default.lb_headerFName;
            lkb_fullName.Text = _userName;
            
            lkb_logout.Text = Properties.Settings.Default.lb_logout;

        }

    }
}